package com.emeraldparser.collect;

import java.util.AbstractSet;
import java.util.Iterator;

public abstract class AbstractTransformedSet<F, T> extends AbstractSet<T> implements TransformedSet<F, T> {

	@Override
	public Iterator<T> iterator() {
		final Iterator<F> sourceIterator = sourceSet().iterator();
		
		return new Iterator<T>() {

			@Override
			public boolean hasNext() {
				return sourceIterator.hasNext();
			}

			@Override
			public T next() {
				return apply(sourceIterator.next());
			}

			@Override
			public void remove() {
				sourceIterator.remove();
			}

		};
	}

	@Override
	public int size() {
		return sourceSet().size();
	}

}
